const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let projectNum;
let peopleArr = [];
let projectValue = [];
let peopleNeedArr = []
rl.on("line", (line) => {
    if (projectNum === undefined) {
        projectNum = Number(line.trim())
    } else if (peopleArr.length === 0) {
        peopleArr = line.trim().split(/\s+/).map(Number)
    } else if (projectValue.length === 0) {
        projectValue = line.trim().split(/\s+/).map(Number)
    } else {
        peopleNeedArr.push(line.trim().split(/\s+/).map(Number))
        if (peopleNeedArr.length === projectNum) {
            console.log(getResult(projectNum, peopleArr, projectValue, peopleNeedArr))

            // clear
            projectNum = undefined
            peopleArr.length = 0
            projectValue.length = 0
            peopleNeedArr.length = 0
        }
    }
})

function getResult(projectNum, peopleArr, projectValue, peopleNeedArr) {
    let peopleObj = {}
    peopleObj.a = peopleArr[0]
    peopleObj.b = peopleArr[1]
    peopleObj.c = peopleArr[2]

    let projectArr = []
    for (let i = 0; i < projectNum; i++) {
        const [a, b, c] = peopleNeedArr[i]
        let obj = {
            a,
            b,
            c,
            value: projectValue[i]
        }
        projectArr.push(obj)
    }

    let map = new Map()
    map.set(`0-0-0`, 0)

    for (const {a, b, c, value} of projectArr) {
        let cloneMap = structuredClone(map)
        for (const key of cloneMap.keys()) {
            const [oldA, oldB, oldC] = key.split("-").map(Number)
            let newA = oldA + a
            let newB = oldB + b
            let newC = oldC + c

            if (newA <= peopleObj.a && newB <= peopleObj.b && newC <= peopleObj.c) {
                let oldValue = map.get(`${newA}-${newB}-${newC}`) || 0
                map.set(`${newA}-${newB}-${newC}`, Math.max(map.get(key) + value, oldValue))
            }
        }
    }

    return Math.max(...map.values())
}